package com.example.shardingjdbc.dao;

import com.example.shardingjdbc.entity.UserDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author: gongjunjie
 * @date: 2022/3/30
 */
public interface UserDetailDao extends JpaRepository<UserDetail,Long> {

    @Query(nativeQuery = true, value = "select u.id,u.username,d.real_name,d.age from user u join user_detail d on u.id = d.user_id where u.id = :uid")
    Object findByPrimaryKey(@Param("uid") Long uid);

    @Query(nativeQuery = true, value = "select u.id,u.username,d.real_name,d.age from user u join user_detail d on u.id = d.user_id where u.username = :username")
    Object findByUserName(@Param("username") String username);

}